#pragma once

#include "resource.h"
#include "FileHandler.h"
#include "FindTextDialog.h"
#include "ViewController.h"
#include "CopyConverter.h"
#include "Copier.h"
#include "CopyProgressWindow.h"
#include <commdlg.h>

static const int kMaxLengthForLoadingString = 100;

class HexApplication
{
	HINSTANCE mInstance;
	HWND mWindow;

	TCHAR mWindowClassName[kMaxLengthForLoadingString];
	TCHAR mWindowInitialTitle[kMaxLengthForLoadingString];

	bool mIsRepeatedFind;
	bool mIsDelayedInvalidation;

	FileHandler mFileHandler;
	ViewController mViewController;
	Copier mCopier;
	CopyProgressWindow mCopyProgressWindow;
	FindTextDialog mFindTextDialog;
	long double mScrollPosition;
	long double mContentHeight;
	double mScaleForScroll;
public:

	bool InitInstance(HINSTANCE);
	bool OpenFile(LPCTSTR filePath, LPCTSTR displayName, bool needStripQuotes);
	void AdjustWindowSize();
	void Show(int cmdShow);
	int Run();

	////
	LRESULT WindowProcedure(UINT message, WPARAM wParam, LPARAM lParam);
private:
	bool ProcessCommand(int commandId);
	bool ProcessOpenCommand();
	void ResetScrollBar();
	void OnScroll(int scrollRequest, int currentPosition);
	void OnWheel(int wheelDelta);
	void ScrollTo(long double scrollPosition, bool shouldBecomeReadyBeforePaint);
	double GetPageHeight(double quantum) const;
	void OnSize(int cx, int cy);
	POINT GetLocalMousePosition(LPARAM) const;
	void InvalidateSelection();
	void BeginCopy(CopyMode, LPCTSTR description);
	void ContinueCopying();
	void CancelCopying();
	void UpdateMenuItemStates(HMENU subMenu);
	void ProtectCachingForOnscreenData(bool);
	void PerformFind(BOOL downwards);
	void FinishFind();
	void CancelFind();
};